package com.myObserver;

/**
 * 具体观察者角色类
 * 
 * @author yulipeng
 *
 */
public class ConcreteObserver implements Observer {

	private String observerState;

	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	/**
	 * 推模型
	 */
	@Override
	public void update(String state) {
		observerState = state;
		System.out.println("我是观察者(推模型)：" + name + "，接收的状态为：" + observerState);
	}

	/**
	 * 拉模型: 这里的参数是抽象类Subject
	 */
	@Override
	public void update(Subject subject) {
		observerState = ((ConcreteSubject) subject).getState();
		System.out.println("我是观察者(拉模型)：" + name + "，接收的状态为：" + observerState);
	}
}
